<?php

use common\models\Blog;
use mdm\admin\components\Helper;
use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel backend\models\BlogSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = 'Blogs';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="blog-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?php
        //没有创建权限不显示按钮
        if (Helper::checkRoute('create')) {
            echo Html::a('Create Blog', ['create'], ['class' => 'btn btn-success']);
        } ?>
    </p>

    <?= GridView::widget([
        'options' => ['id' => 'blog'],
        'dataProvider' => $dataProvider,
       // 'filterModel' => $searchModel,
        'layout'=> '{items}<div class="text-right tooltip-demo">{pager}</div>',
        'pager'=>[
            //'options'=>['class'=>'hidden']//关闭自带分页
            'firstPageLabel'=>"First",
            'prevPageLabel'=>'Prev',
            'nextPageLabel'=>'Next',
            'lastPageLabel'=>'Last',
        ],
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'id',
            'title',
            'content:ntext',
            'views',
            [
                "attribute" => "is_delete",
                "value" => function ($model) {
                    return Blog::dropDown("is_delete", $model->is_delete);
                },
                "filter" => Blog::dropDown("is_delete"),
            ],
            //'is_delete',
            //'created_at',
            //'updated_at',
            ['class' => 'yii\grid\ActionColumn',
                'template' => Helper::filterActionColumn('{view}{update}{delete}'),
            ],
            // pager参数对应了GridView下方分页组件的配置，查看yii\widgets\LinkPager这个类的属性
            /*'pager' => [
                'activePageCssClass' => 'am-active',
                'option' => [
                    'class' => 'am-pagination am-pagination-default',
                ],
            ]*/
        ],
    ]); ?>
</div>
